'''
filename: redis
author: yinwenlu
datetime: 2019/12/13 19:18
software: PyCharm
'''
import redis


class RedisConnect(object):
    def __init__(self):
        """初始化 redis 连接对象"""
        rc = redis.StrictRedis(host='127.0.0.1', port=8888, db=0, password="guangqi")
        self.rc = rc

    def set(self, key, value):
        """向 redis 中插入键值"""
        rest = self.rc.set(key, str(value))
        return True if rest else False

    def get(self, key):
        """从 redis 中用键获取值"""
        value = self.rc.get(key)
        return value if value else None

    def get_my_values(self):
        """获取前四个ip"""
        ip_list = []
        for i in range(4):
            ip_list.append(self.get("".format(i)))
        return ip_list